package com.yanqu.road.server.cmd.kuang;

import com.yanqu.road.entity.kuang.KuangConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kuang.Kuang;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.kuang.CrossKuangMgr;
import com.yanqu.road.server.manager.kuang.activity.CrossKuangActivity;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;

@Cmd(code = CrossProtocol.C_CROSS_KUANG_GET_USER_RANK_LIST, desc = "获取用户榜单")
public class CrossKuangGetUserRankListCmd extends CrossAppointCommand {

    private int groupId;

    private int type;

    private String param;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        Kuang.CrossKuangBattleGetUserRankReqMsg reqMsg = Kuang.CrossKuangBattleGetUserRankReqMsg.parseFrom(packet.getBytes());
        groupId = reqMsg.getGroupId();
        type = reqMsg.getType();
        param = reqMsg.getParam();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossKuangActivity activity = CrossKuangMgr.getActivity(groupId);
        if (activity == null) {
            ret = GameErrorCode.E_KUANG_BATTLE_ACTIVITY_NOT_FOUND;
            return;
        }
        KuangConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_KUANG_CONFIG_NOT_FOUND;
            return;
        }
        activity.getUserRankListByCmd(packet.getPlayerId(), type, param);
    }

    @Override
    public void sendData() {

    }
}
